package cn.bdqn.mallmgr.config;

import cn.bdqn.mallmgr.interceptor.RecInterceptor;
import cn.bdqn.mallmgr.tools.RedisTool;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author
 * @create 2022-07-13 16:13
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    
    @Resource
    private RedisTool redisTool;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加拦截器，添加拦截规则，添加放行规则
        List<String> recPatterns = new ArrayList<>();
        recPatterns.add("/");
        recPatterns.add("/css/**");
        recPatterns.add("/images/**");
        recPatterns.add("/js/**");
        recPatterns.add("/fonts/**");
        recPatterns.add("/index");
        recPatterns.add("/login");
        recPatterns.add("/register");
        recPatterns.add("/address/**");
        recPatterns.add("/productList");
        recPatterns.add("/productDetails");
        registry.addInterceptor(new RecInterceptor(redisTool)).addPathPatterns("/**").excludePathPatterns(recPatterns);


    }
}
